import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { NestExpressApplication } from '@nestjs/platform-express';
import { SwaggerModule, DocumentBuilder } from '@nestjs/swagger';
// const { globalLogger } = require("./shared/logger");
// import { ApiExceptionFilter } from './filter/HttpStatusFilter';
import { JwtAuthGuard } from './auth/jwt-auth.guard';
import { join } from 'path';
// function MiddleWareAll(req: any, res: any, next: any) {
//   next()
// }

async function bootstrap() {
  const app = await NestFactory.create<NestExpressApplication>(AppModule);
  // globalLogger.info("日志内容");

  /**
   * 注册 全局 过滤器 并且只有一个
   */
  // app.useGlobalFilters(new ApiExceptionFilter());

  // app.use(MiddleWareAll) // 注册全局中间件
  // app.useGlobalGuards(new JwtAuthGuard()); //注册守卫

  /**
   * 使用了Express的cors包 配置跨域
   */
  app.enableCors(); //

  app.useStaticAssets(join(__dirname, '../uploads'), { prefix: '/uploads' });

  const config = new DocumentBuilder()
    .setTitle('接口开发文档')
    .setDescription('系统管理后台')
    .setVersion('1.0')
    .addTag('接口文档')
    // .addBearerAuth() // 允许tonken鉴权
    .build();
  const document = SwaggerModule.createDocument(app, config);
  SwaggerModule.setup('doc', app, document);

  await app.listen(3005);
}
bootstrap();
